package com.six.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.six.domain.entity.Category;   // ✅ 正确的实体
import com.six.domain.entity.Dish;
import com.six.domain.vo.MenuRespVo;
import com.six.mapper.CategoryMapper;
import com.six.mapper.DishMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class MenuService {
    private final DishMapper dishMapper;
    private final CategoryMapper categoryMapper;

    @Cacheable(value = "menu", key = "#storeId", unless = "#result == null")
    public MenuRespVo buildMenu(Long storeId) {
        List<Category> categories = categoryMapper.selectList(
                new LambdaQueryWrapper<Category>()
                        .eq(Category::getStoreId, storeId));

        List<Dish> dishes = dishMapper.selectList(
                new LambdaQueryWrapper<Dish>()
                        .eq(Dish::getStoreId, storeId)
                        .eq(Dish::getIsActive, 1));

        return new MenuRespVo(categories, dishes);
    }
}